package com.ease.archiecture.firstdemo.controller;


import com.ease.archiecture.firstdemo.entity.User;
import com.ease.archiecture.springjdbc.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

@Controller
@RequestMapping("/")
public class FirstController {

    @Autowired
    private UserMapper userMapper;


    @RequestMapping(value = "test", method = RequestMethod.GET)
    @ResponseBody
    public String test() {
        return "test success";
    }


    @RequestMapping(value = "testReqV/{name}", method = RequestMethod.GET)
    @ResponseBody
    public String testReqV(@PathVariable String name) {
        return name;
    }

    @RequestMapping(value = "testReqP", method = RequestMethod.GET)
    @ResponseBody
    public String testReqP(@RequestParam String name) {
        return name;
    }

    @RequestMapping(value = "testReqB", method = RequestMethod.POST)
    @ResponseBody
    public String testReqB(@RequestBody User user) {
        return user.getName();
    }


    @RequestMapping(value = "testReqMybatis", method = RequestMethod.GET)
    @ResponseBody
    public String testReqMybatis(@RequestParam String name) {
        return String.valueOf(userMapper.findByName(name).size());
    }




}
